<?php

/*
 * 推送自定义菜单至微信平台
 * 我的按钮生成测试界面
 */

$APPID="wx296743dbebfce339";
$APPSECRET="cd714694d658577b8e0a567da1379f5f ";

$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;

$json=file_get_contents($TOKEN_URL);
$result=json_decode($json,true);
$ACC_TOKEN=$result['access_token'];
//var_dump($ACC_TOKEN);
$data = '{
    "button":[
        {
            "name":"查询成绩",
            "type":"click",
            "key":"search"
        }
    ]
}';
/*
$data = '{
    "button":[
        {
            "name":"我的照片",
            "sub_button":[
                {
                "type":"view",
                "name":"公司简介",
                "url":"http://www.zxec.com/about.asp"
                },
                {
                "type":"view",
                "name":"总裁致辞",
                "url":"http://www.zxec.com/zc.asp"
                },
                {
                "type":"view",
                "name":"发展履历",
                "url":"http://www.zxec.com/developing.asp"
                },
                {
                "type":"view",
                "name":"公司荣誉",
                "url":"http://www.zxec.com/ry.asp"
                },
                {
                "type":"view",
                "name":"企业文化",
                "url":"http://www.zxec.com/jywh.asp"
                }]
        },
        {
            "name":"产品中心",
            "sub_button":[
                {
                "type":"view",
                "name":"消费电子产品",
                "url":"http://www.zxec.com/zycpxfdz.asp"
                },
                {
                "type":"view",
                "name":"通讯产品",
                "url":"http://www.zxec.com/zycptxcy.asp"
                },
                {
                "type":"view",
                "name":"汽车产业",
                "url":"http://www.zxec.com/zycpqccy.asp"
                },
                {
                "type":"view",
                "name":"光学产业",
                "url":"http://www.zxec.com/zycpgxcy.asp"
                }]
        },
        {
            "name":"研究研发",
            "sub_button":[
                {
                "type":"view",
                "name":"中心简介",
                "url":"http://www.zxec.com/yfzw.asp"
                },
                {
                "type":"view",
                "name":"研发展望",
                "url":"http://www.zxec.com/yfzw1.asp?id=15"
                },
                {
                "type":"view",
                "name":"研发专题",
                "url":"http://www.zxec.com/yfzw1.asp?id=15"
                },
                {
                "type":"view",
                "name":"企业文化",
                "url":"http://www.zxec.com/yfzw1.asp?id=18"
                }]
        }
    ]
}';
*/


$MENU_URL="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$ACC_TOKEN;

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $MENU_URL); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$info = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Errno'.curl_error($ch);
}

curl_close($ch);

var_dump($info);
?>
